<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>todolist 组件拆分</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="inputValue">
        <button v-on:click="handleBtnClick">提交</button>
        <ul v-for="(item, index) in list">
            <todo-item :content="item" :index="index" @handleli="handleli"></todo-item>
<!--            <li v-on:click="handleLi(index)">{{item}}+{{index}}</li>-->
        </ul>
    </div>
    <script>
        var TodoItem = Vue.component("TodoItem",{
            props: ["content","index"],
            template: "<li @click='handleLiDel'>{{content}}+{{index}}</li>",
            methods: {
                handleLiDel: function () {
                    this.$emit("handleli",this.index);
                }
            }
        })

        var app = new Vue({
            el:"#app",
            data:{
                list: [],
                inputValue:''
            },
            methods: {
                handleBtnClick: function () {
                    this.list.push(this.inputValue);
                    this.inputValue = '';
                },
                handleli: function (index) {
                    this.list.splice(index, 1)
                }
            },
            components:{
                TodoItem
            }

        })

    </script>
</body>
</html>